package gitee.cheungming.modules.governance.controller;


import cn.dev33.satoken.oauth2.annotation.SaCheckClientToken;
import cn.dev33.satoken.util.SaResult;
import gitee.cheungming.modules.governance.domain.EventData;
import gitee.cheungming.modules.governance.service.EventService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Timestamp;


@SaCheckClientToken
@Controller
@RequestMapping("/api/event")
public class EventController {

    @Resource
    EventService eventService;

    @ResponseBody
    @RequestMapping("/ingestion/{count}")
    public SaResult ingestion(@PathVariable Long count) {
        eventService.ingestion(eventService.createData(count));
        return SaResult.ok();
    }

    @ResponseBody
    @RequestMapping("/queryLatest/{vin}")
    public SaResult queryLatest(@PathVariable String vin) {
        EventData data = eventService.queryLatest(vin);
        return SaResult.data(data);
    }


    @ResponseBody
    @RequestMapping("/queryHistory")
    public SaResult queryHistory(@RequestParam String vin,
                                 @RequestParam Timestamp start,
                                 @RequestParam Timestamp end) {
        return SaResult.data(eventService.queryHistory(vin, start, end));
    }

}
